//
//  DataStorageViewController.m
//  GCD
//
//  Created by fangyuan ding on 2020/8/12.
//  Copyright © 2020 fangyuan ding. All rights reserved.
//

#import "DataStorageViewController.h"
#import "KeyedArchiverViewController.h"
#import "PlistViewController.h"
#import "UserDefaultViewController.h"
@interface DataStorageViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)NSArray *titleArray;

@end

@implementation DataStorageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   self.titleArray = @[@"Arciver",@"Plist",@"NSUserDefault",@"SQLite",@"CoreData"];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}

#pragma mark - Table view data source



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = self.titleArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.row == 0){
        KeyedArchiverViewController *archiver = [[KeyedArchiverViewController alloc]init];
        [self.navigationController pushViewController:archiver animated:YES];
    }else if(indexPath.row == 1){
       PlistViewController *plist = [[PlistViewController alloc]init];
        [self.navigationController pushViewController:plist animated:YES];
    }else if(indexPath.row == 2){
       UserDefaultViewController *userDefault = [[UserDefaultViewController alloc]init];
        [self.navigationController pushViewController:userDefault animated:YES];
    }
}


@end
